iT邦幫忙

第 12 屆 iThome 鐵人賽

DAY 1
0
自我挑戰組

霍普菜鳥的資訊工作雜記系列 第 22

D22-使用koa測試網路2

  • 分享至 

  • xImage
  •  
var nsP = new nsPing();
var ew = new echoHttp();
var nsF = new nsFetch();
var config;
global["fetch"] = fetch; //for d3
nsF.on("result", (target, data) => {
    data.shift();
    let dd = summary(data);
    dd['target'] = target.split(":")[1].substr(2,100);
    dd['type'] = 'fetch';
    dd['logtime'] = new Date().toISOString();
    dd['host'] = hostname
    dp.update([{k:Date.now(),v:dd}]);
    dp.merge();
    console.log("fetch==>",target, summary(data));
    collectData()    
});
nsP.on("result", (target, data) => {
    data['type'] = 'ping';
    data['logtime'] = new Date().toISOString();
    data['host'] = hostname;
    dp.update([{k:Date.now(),v:data}]);
    dp.merge();
    console.log("ping==>",target, data);
    collectData();
});

var targets = []

var dp = new pool(dataServer, () => {
    dp.openSocket();
    dp.onSocketDataUpdate = d => {
        dp.update(d);
        dp.mergeLocal(false);
    };
    ew.launch(echoPort);
    dp.update([{ k: hostname, v: { ip: adds, httpEchoPort: echoPort } }]);
    dp.merge();
    //console.log(dp.dump());
    config = dp.get('config');
    setInterval(() => {
            targets = [];
            dp.dump().filter(d=>d.v['ip']).forEach(t=>{
                console.log(t.v);
                (<string[]>t.v["ip"]).forEach(d => {
                    targets.push({type:"ping",ip:d});
                    targets.push({type:"fetch",ip:d,port:t.v['httpEchoPort']});
                });
            });
            console.log("targets");
            console.log(targets);
            collectData();
        }
    , config.resampleFreq)
});

function collectData() {
    //console.log(targets);
    let target:{type:string,ip:string,port:number} = targets.shift();
    console.log(target);
    if (target)
    if (target.type === 'ping') nsP.sample(target.ip,config.sampleSize);
    else nsF.sample(`http://${target.ip}:${target.port}`,config.smallDataSize, config.sampleSize,config.delay);
    // targets[currentTargetIP].
}

上一篇
D21-使用koa測試網路1
下一篇
D23-試試新玩意Deno
系列文
霍普菜鳥的資訊工作雜記31
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言